<template>
  <div>
    <!--条件筛选-->
    <TopFilter :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!--操作 -->
    <button-area :style="{ paddingLeft: '80px' }"></button-area>
    <!-- 列筛选-->
    <FilterTable
      ref="table"
      columnsRef="whmQueryPickUpOrder"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      selectionType="single"
      :datakey="'rows'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="selectData"
    >
      <!--列操作-->
      <template slot="controls">
        <el-button size="small" type="primary" @click="electronization">电子化</el-button>
        <el-button size="small" type="primary" @click="queryPickUpOrder">打印接车单</el-button>
      </template>
    </FilterTable>
    <!--打印接车单-->
    <BasePrint ref="print" :data="printList" template="queryPickUpOrder" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import { getUserListSelect } from '@/api/report/repair/repairreport';
import { getQueryPickUpOrder } from '@/api/repair/queryStatistics/queryAccounts';
import { getQueryPickUpOrderPrint } from '@/api/repair/queryStatistics/queryAccounts';
import { receptionOrder } from '@/api/repair/queryStatistics/queryAccounts';

import dictCode from '@/utils/dictCode';
export default {
  name: 'whmQueryPickUpOrder',
  components: {},
  mixins: [dictionary],
  data() {
    this.conf = { add: '新增', delete: '删除', edit: '编辑', show: '显示' };
    return {
      topFilterList: this.createTopFilterList(),
      fetchParams: {},
      printList: {},
      visible: false,
      visible1: false,
      dialogTitle: '',
      fetchApi: getQueryPickUpOrder,
      columns: this.createTableColumns(),
      handleType: '',
      formData: {},
      jcNo: '',
      tableData: [],
      ids: []
    };
  },
  mounted() {
    // 分页
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.initSelect();
  },
  methods: {
    async initSelect() {
      // 服务顾问
      let testDrive = { role: dictCode.SERVICE_CONSULTANT };
      let res5 = (await searchRoleByCode(testDrive)).data.map(x => ({ value: x.userId + '', text: x.employeeName }));
      this.topFilterList.find(item => item.fieldName === 'SERVICE_ADVISOR').itemList = res5;
      this.columns.find(x => x.dataIndex === 'ADVISOR_NAME').dictItems = res5;
      this.columns.find(x => x.dataIndex === 'ADVISOR_NAME').filterItems = res5;
    },
    // 接车单打印方法
    async jcdPrintList() {
      const jcNo = this.tableData[0].RECEPTION_NO;
      let res2 = getQueryPickUpOrderPrint(jcNo); // 获取打印主数据
      let res = await res2;

      // let res1 = await res3;
      if (res.resultCode == 200) {
        this.printList = _.cloneDeep(res.data);
        let oilRemain = this.printList.mainInfo.OIL_REMAIN;
        const oilRes = this.createDictList('8045');

        for (var i = 0; i < oilRes.length; i++) {
          if (oilRemain === oilRes[i].value) this.printList.mainInfo.OIL_REMAIN = oilRes[i].text;
        }
        this.$refs.print.EXCUTE_PRINT();
      }
    },
    createTopFilterList() {
      return [
        {
          type: 'RANGE_DATE',
          label: '接车日期',
          fieldName: 'beginDate|endDate',
          placeholder: '选择日期'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license'
        },
        {
          type: 'SELECT',
          label: '服务顾问',
          fieldName: 'SERVICE_ADVISOR',
          initialValue: '',
          itemList: []
        }
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '接车单号',
          dataIndex: 'RECEPTION_NO',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '用户名称',
          dataIndex: 'OWNER_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '服务顾问代码',
          dataIndex: 'ADVISOR_CODE',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'input'
        },
        {
          title: '服务顾问名称',
          dataIndex: 'ADVISOR_NAME',
          sorter: true,
          filter: true,
          showOverflowTooltip: true,
          filterType: 'checkbox',
          filterItems: [],
          dictItems: []
        },
        {
          title: '接车日期',
          dataIndex: 'RECEPTION_DATE',
          width: 150,
          dateFormat: 'yyyy-MM-dd',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          editable: false,
          editType: 'date-picker'
        },
        {
          title: '是否全面检查',
          dataIndex: 'DEPTH_CHECK',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    // 接车单打印
    queryPickUpOrder() {
      if (this.tableData.length > 0) {
        this.jcdPrintList();
      } else {
        this.$notify.warning({ title: '提示信息', message: '请选择一条接车单信息！' });
      }
    },
    // 电子化
    async electronization() {
      if (this.tableData.length > 0) {
        const orderNo = this.tableData[0].RECEPTION_NO;
        const res = await receptionOrder({ orderNo: orderNo });
        if (res.resultCode == 200) {
          this.$notify.success({ title: '提示信息', message: '操作成功!' + res.data.message });
        }
      } else {
        this.$notify.warning({ title: '提示信息', message: '请选择一条接车单信息！' });
      }
    },
    selectData(val) {
      this.tableData = val;
    },
    addHandle() {
      // 新建
      this.handleType = 'add';
      // this.formData = row;
      this.showHandler();
    },
    editHandle(row) {
      this.handleType = 'edit'; // 编辑

      this.showHandler();
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    // async saveDialog() {
    //   let res = {};
    //   if(this.tableData==null) return
    //     res = await addCustomeRgradeUpdatet({customeRgradeUpdateDTOList:this.tableData });
    //   if (res.resultCode === 200) {
    //     this.closeDialog('refresh');
    //   }
    // },
    showHandler() {
      // 显示
      this.dialogTitle = `查看结算记录`;
      this.visible = true;
    },
    closeHandler(val, type) {
      // 关闭
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
